package com.fh.config;

import com.fh.exception.HouseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * springmvc全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class SpringMvcAdviceException {

    @ExceptionHandler(Exception.class)
    public void exception(Exception e) {

        log.error("最大的异常处理", e);
        //System.out.println("最大的异常统一处理");
    }

    @ExceptionHandler(HouseException.class)
    public void foodExceptione(HouseException e) {
        System.out.println("自定义异常统一处理");
    }

    @ExceptionHandler(BindException.class)
    public String bindException(BindException e) {
        return e.getBindingResult().getFieldError().getDefaultMessage();
    }


}
